package com.jsh.wiki.service;

import com.jsh.wiki.domain.Ebook;
import com.jsh.wiki.domain.EbookExample;
import com.jsh.wiki.mapper.EbookMapper;
import com.jsh.wiki.req.EbookReq;
import com.jsh.wiki.resp.EbookResp;
import com.jsh.wiki.util.CopyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EbookService {
    @Resource
    private EbookMapper ebookMapper;
    public List<EbookResp> list(EbookReq ebookReq){
        EbookExample ebookExample = new EbookExample();
       EbookExample.Criteria criteria=ebookExample.createCriteria();
       criteria.andNameLike("%"+ebookReq.getName()+"%");
        List<Ebook> ebooks = ebookMapper.selectByExample(ebookExample);
//        List<EbookResp> ebookResps=new ArrayList<>();
//        for (Ebook ebook : ebooks) {
////            EbookResp ebookResp = new EbookResp();
////            BeanUtils.copyProperties(ebook,ebookResp);
//            EbookResp copy = CopyUtil.copy(ebook, EbookResp.class);
//            ebookResps.add(copy);
//
//        }
        List<EbookResp> list= CopyUtil.copyList(ebooks, EbookResp.class);
        return list;
    }
}
